﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Net;
using System.Text.RegularExpressions;
using System.Text;
using System.DirectoryServices;
using System.Web.Mail;
using WdpaLoginServiceRef;

public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (User.Identity.IsAuthenticated)
        {
            lblLoginStatus.Text = "You are logged in";
        }

    }
    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        string usrEmail = Login1.UserName;
        string usrPassword = Login1.Password;

        WdpaLoginService wdpaLoginService1 = new WdpaLoginService();

        //Returns a string of either: 'AllowLogin', 'UpdateAccount', 'NotActivated', 'LoginError' 
        string strLoginStatus = wdpaLoginService1.getLoginStatus(usrEmail, usrPassword);

        if (strLoginStatus == "AllowLogin")
        {
            e.Authenticated = true;
        }
        else if (strLoginStatus == "UpdateAccount")
        {
            //Send to update page
            Session["usrEmail"] = usrEmail;
            Session["MigrateUser"] = "true";

            Response.Redirect("UpdateAccount.aspx");
        }
        else if (strLoginStatus == "NotActivated")
        {
            wdpaLoginService1.CreateUser_SendingMail(usrEmail);
            Login1.FailureText = "Our records show that your account has not been activated.  A new activation email has been sent to your account.";

        }
        else
        {
            //LoginError
            Login1.FailureText = "Login error. Please try again.";
        }
    }
}